//
//  Bx_AfnNetManager.h
//  BiXuan
//
//  Created by ayi on 2018/7/24.
//  Copyright © 2018年 BSNL. All rights reserved.
//

/**
 
 
 */
#import <Foundation/Foundation.h>

#import <AFNetworking/AFNetworking.h>
#import "BaseNetModel.h"

typedef NS_OPTIONS(NSUInteger, BX_NetWorkStatus) {
    StatusUnknown          = 0, //未知网络
    StatusReachableViaWiFi = 1,//wifi网络
    StatusReachableViaWAN  = 2,//手机网络
    StatusNoReachable      = 3,//没有网络
};

NS_ASSUME_NONNULL_BEGIN

typedef void (^ ResponseCache)(id response);
typedef void (^ ResponseSuccess)(_Nullable id response);
typedef void (^ ResponseFail)(NSError *error);
typedef void (^ LogicError)(id response);
typedef void (^ UploadProgress)(int64_t bytesProgress,int64_t totalBytesProgress);
typedef void (^ DownloadProgress)(int64_t bytesProgress,int64_t totalBytesProgress);

@interface ZY_AfnNetManager : NSObject


@property (nonatomic, strong) AFHTTPSessionManager *manager;
/**
 *  获取网络
 */
@property (nonatomic,assign) BX_NetWorkStatus networkStats;
/**
 AFNet_Manager
 
 @return 实例
 */
+ (ZY_AfnNetManager *)shareInstance;

/**
 默认网络请求设置
 
 @return AFHTTPSessionManager
 */
+ (AFHTTPSessionManager *)defaultSessionManager;

/**
 开启网络监控
 */
+ (void)startMonitoring;


/**
 取消所有的请求
 */
+ (void)cancelAllRequest;
/**
 根据url取消请求
 */
+ (void)cancelAppointRequest:(NSString *)url;
/**
 根据task取消请求
 */
+ (void)cancelAppointTaskt:(NSURLSessionTask *)task;
/**
 设备唯一码
 */
//- (NSString *)getUniqueDeviceIdentifierAsString;
/**
 签名
 */

/**
 GET 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @return 返回请求task
 */
- (NSURLSessionTask *)getWithURL:(NSString *)url
                          params:(nullable NSDictionary *)params
                     md5Paraname:(nullable NSString *)md5name
                         success:(ResponseSuccess )success
                            fail:(ResponseFail )fail;

/**
 GET 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @return 返回请求task
 */
- (NSURLSessionTask *)getWithURL:(NSString *)url
                          params:(nullable NSDictionary *)params
                     md5Paraname:(nullable NSString *)md5name
                   responseCache:(ResponseCache )cachecallback
                         success:(ResponseSuccess )success
                            fail:(ResponseFail )fail;

/**
 　POST 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @return 返回请求task
 */
- (NSURLSessionTask *)postWithURL:(NSString *)url
                           params:(nullable id)params
                      md5Paraname:(nullable NSString *)md5name
                          success:(ResponseSuccess)success
                             fail:(ResponseFail )fail;


/**
 　POST 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @param cachecallback 返回cache
 @return 返回请求task
 */
- (NSURLSessionTask *)postWithURL:(NSString *)url
                           params:(nullable id)params
                      md5Paraname:(nullable NSString *)md5name
                    responseCache:(ResponseCache )cachecallback
                          success:(ResponseSuccess)success
                             fail:(ResponseFail )fail;

/**
 上传图片方法

 @param image      上传的图片
 @param url        请求连接，根路径
 @param fileName   图片的名称(如果不传则以当时间命名)
 @param name       上传图片时填写的图片对应的参数
 @param params     参数
 @param progress   上传进度
 @param success    请求成功返回数据
 @param fail       请求失败

 @return 上传操作的task
 */
- (NSURLSessionTask*) uploadWithImage:(UIImage *)image
                                  url:(NSString*)url
                             fileName:(NSString*)fileName
                                 name:(NSString*)name
                               params:(NSDictionary*)params
                             progress:(UploadProgress )progress
                              success:(ResponseSuccess )success
                                 fail:(ResponseFail )fail;




/**
 GET 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @param requestModel 自定义requestmodel
 @return 返回请求task
 */
- (NSURLSessionTask *)getWithURL:(NSString *)url
                          params:(nullable NSDictionary *)params
                     md5Paraname:(nullable NSString *)md5name
                         request:(nullable BaseNetRequestModel *)requestModel
                        response:(nullable BaseNetResponseModel *)responseModel
                         success:(ResponseSuccess )success
                            fail:(ResponseFail )fail;

/**
 GET 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @param requestModel 自定义requestmodel
 @param cachecallback 返回cache
 @return 返回请求task
 */
- (NSURLSessionTask *)getWithURL:(NSString *)url
                          params:(nullable NSDictionary *)params
                     md5Paraname:(nullable NSString *)md5name
                         request:(nullable BaseNetRequestModel *)requestModel
                        response:(nullable BaseNetResponseModel *)responseModel
                   responseCache:(ResponseCache )cachecallback
                         success:(ResponseSuccess )success
                            fail:(ResponseFail )fail;

/**
 　POST 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @param requestModel 自定义requestmodel
 @return 返回请求task
 */
- (NSURLSessionTask *)postWithURL:(NSString *)url
                           params:(nullable id)params
                      md5Paraname:(nullable NSString *)md5name
                          request:(nullable BaseNetRequestModel *)requestModel
                         response:(nullable BaseNetResponseModel *)responseModel
                          success:(ResponseSuccess)success
                             fail:(ResponseFail )fail;
/**
 　POST 请求
 
 @param url     请求连接的URL
 @param params  请求参数
 @param success 请求成功回调
 @param fail    请求失败回调
 @param requestModel 自定义requestmodel
 @param cachecallback 返回cache
 @return 返回请求task
 */
- (NSURLSessionTask *)postWithURL:(NSString *)url
                           params:(nullable id)params
                      md5Paraname:(nullable NSString *)md5name
                          request:(nullable BaseNetRequestModel *)requestModel
                         response:(nullable BaseNetResponseModel *)responseModel
                    responseCache:(ResponseCache )cachecallback
                          success:(ResponseSuccess)success
                             fail:(ResponseFail )fail;






//传自定义的url。不参与任何其他默认处理
- (NSURLSessionTask *)getDataFromUrl:(NSString *)url
                           params:(nullable id)params
                          success:(ResponseSuccess)success
                             fail:(ResponseFail )fail;



@end

NS_ASSUME_NONNULL_END
